import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import viteEslint from 'vite-plugin-eslint';
import { fileURLToPath } from 'url';
import path from 'path';

const __filenameNew = fileURLToPath(import.meta.url);

const __dirname = path.dirname(__filenameNew);

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    viteEslint({
      failOnError: false, // 开发环境时遇到eslint问题是否中断程序
      include: [
        // (注意以下配置只会再项目运行时生效)  include 配置哪些文件再运行时需要进行eslint校验
        'src/**/*.txs',
        'src/**/*.js',
        'src/**/*.ts',
        'src/*.tsx',
        'src/*.jsx'
      ]
    })
  ],

  // 配置别名
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components'),
      '@utils': path.resolve(__dirname, './src/utils')
    }
  },
  // 配置代理
  server: {
    open: true,
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:7100',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
});
